//
//  JZHMyPingViewController.m
//  极致荟
//
//  Created by hetao on 14-8-6.
//  Copyright (c) 2014年 mac. All rights reserved.
//

#import "JZHMyPingViewController.h"
#import "JZHHouTableViewCell.h"
#import "JZHReview.h"
#import "OtherUsers.h"
@interface JZHMyPingViewController ()
{
    NSMutableArray *dataarr;
}
@end

@implementation JZHMyPingViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setAutomaticallyAdjustsScrollViewInsets:NO];
    self.navigationItem.title=@"我的评论";
    dataarr=[[NSMutableArray alloc]init];
    [self.table registerClass:[JZHHouTableViewCell class] forCellReuseIdentifier:@"HOU"];
    UIButton *leftButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 12, 20)];
    [leftButton addTarget:self action:@selector(leftDrawerButtonPress:) forControlEvents:UIControlEventTouchUpInside];
    [leftButton setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
    self.navigationItem.leftBarButtonItem = leftBarButton;
    [self httpLoadData];
}
- (void)leftDrawerButtonPress:(UIButton *)but
{
    [UINavigationController Pop:self];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -------table代理------
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return dataarr.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 95;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *str=@"hou";
    JZHHouTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:str];
    if(!cell)
    {
        cell=[[NSBundle mainBundle] loadNibNamed:@"JZHHouTableViewCell" owner:self options:nil][0];
    }
    [cell addCellData:dataarr[indexPath.row]];
    
    return cell;
}

- (void)httpLoadData
{
    NSDictionary *dic=[[NSDictionary alloc]initWithObjectsAndKeys:[NSNumber numberWithInt:[User defuceUser].userId],@"userId", nil];
    [HttpRequest httpRequestPost:JZHHTTPURL(@"myInformation/myComment") parameters:dic block:^(id data, HttpReturnCode rerurncode) {
        if(rerurncode==0)
        {
            NSLog(@"%@",data);
            for(NSDictionary *datadic in [[data objectForKey:@"data"] objectForKey:@"list"])
            {
                JZHReview *rev=[[JZHReview alloc]init];
                OtherUsers *ouser=[[OtherUsers alloc]init];
                rev.comment=[datadic objectForKey:@"content"];
                rev.revdate=[NSDate dateWithTimeIntervalSince1970:[[datadic objectForKey:@"addTime"] longLongValue]];
                ouser.username=[datadic objectForKey:@"userName"];
                ouser.userHeadImage=[[[data objectForKey:@"data"] objectForKey:@"imgPrefix"] stringByAppendingString:[datadic objectForKey:@"avatar"]];
                rev.recUser=ouser;
                [dataarr addObject:rev];
            }
            [self.table reloadData];
        }
    }];
}
@end
